/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.forum.ui;

import com.alee.laf.list.WebListCellRenderer;
import com.alee.laf.list.WebListElement;
import com.rag.core.Item;
import com.rag.core.ItemData;
import com.rag.managers.RagManager;
import com.rag.utils.RagUtils;

import javax.swing.*;
import java.awt.*;

/**
 * User: mgarin Date: 05.04.12 Time: 13:12
 */

public class ItemListCellRenderer extends WebListCellRenderer
{
    public Component getListCellRendererComponent ( JList list, Object value, int index,
                                                    boolean isSelected, boolean cellHasFocus )
    {
        Item item;
        if ( value instanceof ItemData )
        {
            item = RagManager.getItem ( ( ( ItemData ) value ).getItemId () );
        }
        else
        {
            item = ( Item ) value;
        }

        WebListElement renderer = ( WebListElement ) super
                .getListCellRendererComponent ( list, value, index, isSelected, cellHasFocus );
        renderer.setIcon ( item.getSmallIcon () );
        renderer.setText ( RagUtils.getItemText ( item ) );
        return renderer;
    }
}